<template>
<slot :controller="controller" :store="store" :model="model">
    <AppMDViewLayout :class="classNames" :openType="openType">
        <template #viewHeaderContentLeft >
      		<div v-if="model.showCaption && !noViewCaption" class="view-header__caption">
                <slot name="ViewCaption" :controller="controller" :store="store" :model="model">
                    <AppCaptionBar :caption="model.caption" :title="model.title" :capPSLanguageRes="model.capPSLanguageRes" :titlePSLanguageRes="model.titlePSLanguageRes" :openType="openType"></AppCaptionBar>
                </slot>
            </div>
            <div class="view-header__quickgroup">
                <slot name="ViewQuickGroup" :controller="controller" :store="store" :model="model" :actions="{ handleQuickGroupValueChange }">
                <AppQuickGroup :codeListTag="model.quickGroupCodeList" @value-change="(item: IParam) => handleQuickGroupValueChange(controller, item)"></AppQuickGroup>
                </slot>
            </div>
    	</template>
    	<template #viewHeaderContentRight  >
            <div class="view-header__quicksearch" v-show="!store.expandSearchForm">
                <slot name="ViewQuickSearch" :controller="controller" :store="store" :model="model" :actions="{ handleQuickSearch }">
                <AppQuickSearch @search="(searchValue:string) => handleQuickSearch(controller, searchValue)" :placeholder="model.quickSearchPlaceholder"/>
                </slot>
            </div>
            <div class="view-headert__toolbar">
                <slot name="ViewToolbar" :controller="controller" :store="store" :model="model" :actions="{ handleToolbarItemClick }">
                    <AppToolbar
                        name="toolbar"
                        mode="DEFAULT"
                        :items="store.toolbarItems"
                        :loading="store.loadingHelper.isLoading"
                        @item-click="(name: string, event: MouseEvent, logic: any) => { handleToolbarItemClick(controller, name, event, logic) }">
                    </AppToolbar>
                </slot>
            </div>
    	</template>
		<template v-slot:[searchFormSlotName]>
			<slot name="IBIZBOOKDefaultSearchForm" :controller="controller" :store="store" :model="model" :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
			    <IBIZBOOKDefaultSearchForm
			        :actions="{
			            loadDraftAction: 'GetDraft'
			        }"
			        name="searchform"
			        v-bind="model.ctrlParams.IBIZBOOKsearchform"
			        :context="store.context"
			        :viewParams="store.viewParams"
			        :closeView="store.closeView"
			        :pLoadingHelper="store.loadingHelper"
			        :pViewCtx="store.viewCtx"
			        @ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
			        @ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
			        @ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }"    />
			</slot>
		</template>
        <template #default>
            <slot name="IBIZBOOKUsrDataView" :controller="controller" :store="store" :model="model" :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
            <IBIZBOOKUsrDataView
                :rowActiveMode='model.rowActiveMode'
                :actions="{
                    createAction: 'Create',
                    fetchAction: 'FetchDefault',
                    removeAction: 'Remove',
                    updateAction: 'Update'
                }"
                :openView="store.openView"
                :newView="store.newView"
                name="dataview"
                v-bind="model.ctrlParams.IBIZBOOKdataview"
                :context="store.context"
                :viewParams="store.viewParams"
                :closeView="store.closeView"
                :pLoadingHelper="store.loadingHelper"
                :pViewCtx="store.viewCtx"
                @ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
                @ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
                @ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }"/>
            </slot>
        </template>
  	</AppMDViewLayout>
</slot>
</template>
<script setup lang="ts">
// 基于template/src/views/{{appModules}}/{{pages@DEDATAVIEW}}/{{spinalCase page.codeName}}-base.vue.hbs生成
import { AppMDViewLayout } from '@components/layout/md-view-layout';
import IBIZBOOKQUICKSEARCHFORMSearchForm from '@widgets/ibizbook/quicksearchform-searchform/quicksearchform-searchform.vue';
import IBIZBOOKDefaultSearchForm from '@widgets/ibizbook/default-searchform/default-searchform.vue';
import { AppToolbar } from '@components/widgets/toolbar';

import IBIZBOOKUsrDataView from '@widgets/ibizbook/usr-data-view/usr-data-view.vue';
import { useProps, useBasic, useAction, useController } from './ibizbook-data-view-hook';
import { IEvent, DataViewActionType, IDataViewAbility, IDataViewStore, IParam } from '@/core';
// 输入参数
const props = defineProps(useProps());

// 基础数据
const { 
	getClassNames, 
	getSearchFormSlotName, 
	model, 
	useNavParamsBind,
	useEventBind,
  	handleQuickGroupValueChange,
  	handleQuickSearch,
  	handleToolbarItemClick,
    handleComponentAction,
	handleCtrlAction,
	handleCtrlInit,
	handleCtrlDestroy } = useBasic(props);
const emit = defineEmits<{
    (event: 'view-action', name: string, action: DataViewActionType, data: IParam[]): void;
    (event: 'view-init', name: string, data: IDataViewAbility): void;
    (event: 'view-mounted', name: string, data: IParam): void;
    (event: 'view-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);  
const classNames = computed(() => {
  	return getClassNames(props);
});

const searchFormSlotName = computed(() => {
  	return getSearchFormSlotName(props);
});

// 初始化控制器
const controller = useController(props, evt);

useNavParamsBind(controller, props);

const store: IDataViewStore = controller.getStore();

onMounted(() => {
    controller.viewMounted();
})

onUnmounted(() => {
    controller.viewDestroy();
})
</script>
